//
//  ZyaDepositMgtVC.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2020/3/16.
//  Copyright © 2020 zwb. All rights reserved.
//

import UIKit

class ZyaDepositMgtVC: UITableViewController,getDepositRemainable {
 
fileprivate let expectMenuList = ["缴纳保证金","退款申请","资金流水"]
 
    private var showMenuItemList = [MenuItem]()

   
    let helper = ZyaTenderHelper()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self .navigationController?.navigationBar.setBackgroundImage(UIImage.from(color: Theme.primaryColor()), for: .any, barMetrics: .default)
        self .navigationController?.navigationBar.shadowImage = UIImage()
        self .navigationController?.navigationBar.isTranslucent = false
         
    }
    var header : UIView  = {
        var v = UIView(frame: CGRect(x: 0, y: 0, width: KSGlobal.screenW, height: 100))
        v.backgroundColor = Theme.primaryColor()
        return v
    }()
    var yeLab:UILabel = {
        var v = UILabel()
        v.text = "余额(元)"
        v.textColor = .white
        return v
    }()
    var deposit:UILabel = {
        var v = UILabel()
        v.text = "--"
        v.textColor = .white
        return v
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "保证金管理"
         let expectMenuItemList = expectMenuList.compactMap { one -> MenuItem? in
            let mArr = MenuPool.filter{ $0.desc.unwrap == one}
            return mArr.first
        }
        tableView.register(ZyaDepositMgmtCell.self, forCellReuseIdentifier: ZyaDepositMgmtCell.identifier)
        showMenuItemList = expectMenuItemList
        header.addSubview(yeLab)
        header.addSubview(deposit)
        yeLab.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(15)
        }
        deposit.snp.makeConstraints { make in
            make.left.equalTo(yeLab)
            make.top.equalTo(yeLab.snp.bottom).offset(15)
        }
        getDepositValue(valueClo: { (flag,value) in
             self.deposit.text = value
        })
        tableView.tableHeaderView = header
        tableView.rowHeight = 50
        tableView.tableFooterView = UIView()
    }
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return showMenuItemList.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        guard let cell = tableView.dequeueReusableCell(withIdentifier: ZyaDepositMgmtCell.identifier, for: indexPath) as? ZyaDepositMgmtCell else {
            fatalError("cell error")
        }
        cell.titleLab.text = showMenuItemList[indexPath.row].title
        cell.img.image = UIImage(named: showMenuItemList[indexPath.row].imgStr.unwrap)
         return cell
    }
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        // enter
        let one = self.showMenuItemList[indexPath.row].enterFunc
       one!(self)
         
    }
    
    
}
